# $Id: settings.py 7557b5d4d82b 2012/12/02 09:07:16 pgurumur $
# Copyright (c) 2009 Prabhu Gurumurthy  <pgurumur@gmail.com>
# 
# Permission to use, copy, modify, and distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#

import os
import random
import string

__version__ = "$Revision: 7557b5d4d82b $"
__author__ = "$Author: pgurumur $"

# -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

ROOT_PATH  = os.path.dirname(__file__)
def absolute(*Args):
   return os.path.join(ROOT_PATH, *Args)

def relative(*Args):
   return os.path.join(ROOT_PATH.split("/")[-1], *Args)

def templates(*Args):
   return absolute('www', 'templates', *Args)

def mtemplates(*Args):
   return absolute('www', 'templates', 'mobile', *Args)

def djanetString(Length = 128):
   retval = ""
   for ix in xrange(Length):
      retval += random.choice(string.printable[1:63])

   assert len(retval) == Length
   return retval

TMPDIR = absolute("var", "tmp")

CRYPTO = {
      'ENC' : 'AES',
      'SECRET' : 'AllInOne'
      }

RADIUS = {
      'SERVER' : '10.57.132.21',
      'SECRET' : 'K1J6wexbkNpWfRstVrt3wm83',
      'TIMEOUT' : 3
      }

SVN_INFO = {
      'URL' : 'http://foo.bar.com/backups',
      'MOD' : 'backups',
      'USER' : 'foobar',
      'PASS' : 'goofoo',
      'DIR' : absolute('var'),
      }

TEMPLATES = {
      'FORBIDDEN' : templates('djanet403.html'),
      'NOTFOUND'  : templates('djanet404.html'),
      'INTERROR'  : templates('djanet500.html'),
      'NOTALLOWED' : templates('djanet405.html'),
      'BGPPEER'    : templates('bgppeer.html'),
      'RFC4193'   : templates('rfc4193.html'),
      'WHOIS' : templates('whois.html'),
      'NAGIOS' : templates('host.dctl'),
      }

MTEMPLATES = {
      'LOGIN' : mtemplates('login.html'),
      'NETENG' : mtemplates('neteng.html'),
      'WHOIS' : mtemplates('whois.html'),
      'DBLIST' : mtemplates('dblist.html'),
      }

DB_MODELS = {
      'djauth' : 'djanet',
      }

GRIDAPP = []

ASN_URL = 'http://www.iana.org/assignments/as-numbers/as-numbers.xml'
IP_URL = 'http://www.iana.org/assignments/ipv4-address-space/ipv4-address-space.xml'
RFC_URL = 'http://www.rfc-editor.org/rfc/';

SESSION_EXPIRY = 1800
SESSION_COOKIE_AGE = 28800
SESSION_COOKIE_NAME = 'djanet'
SESSION_EXPIRE_AT_BROWSER_CLOSE = True
SESSION_SAVE_EVERY_REQUEST = False
PERSISTENT_SESSION_KEY = djanetString(random.randint(20, 128))
SESSION_KEY = djanetString(random.randint(15, 128))
MAX_RFC = 6100
LOGIN_URL = "/django/djanet/admin/"

# -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

AUTHENTICATION_BACKENDS = (
      'djanet.djauth.backends.Local',
      'djanet.djauth.backends.Radius',
      )


# -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
DEBUG = True
TEMPLATE_DEBUG = DEBUG
MODEL_DEBUG = DEBUG

ADMINS = (
      ('Prabhu Gurumurthy', 'pgurumur@gmail.com'),
)

MANAGERS = ADMINS

DATABASES = {
      'default': {
         'NAME': 'netdot',
         'ENGINE': 'django.db.backends.mysql',
         'USER': 'djanet',
         'PASSWORD': 'oS9XckUcTAHc5rjlcPt1',
         'HOST': 'sirius.kashyapa.net',
         'PORT': '3306',
      },
      'ssn': {
         'NAME' : 'ssn',
         'ENGINE': 'django.db.backends.mysql',
         'USER': 'netops',
         'PASSWORD': 'h3ng2l0dmIIOq2OTaex1',
         'HOST': 'localhost',
         'PORT': '3306',
      }
}

DATABASE_ROUTERS = ['djanet.db.db.AppRouter']

# Local time zone for this installation. Choices can be found here:
# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
# although not all choices may be available on all operating systems.
# If running in a Windows environment this must be set to the same as your
# system time zone.
TIME_ZONE = 'America/Los_Angeles'

# Language code for this installation. All choices can be found here:
# http://www.i18nguy.com/unicode/language-identifiers.html
LANGUAGE_CODE = 'en-us'

SITE_ID = 1

# If you set this to False, Django will make some optimizations so as not
# to load the internationalization machinery.
USE_I18N = True

# Absolute path to the directory that holds media.
# Example: "/home/media/media.lawrence.com/"
MEDIA_ROOT = absolute('media')

# URL that handles the media served from MEDIA_ROOT. Make sure to use a
# trailing slash if there is a path component (optional in other cases).
# Examples: "http://media.lawrence.com", "http://example.com/media/"
MEDIA_URL = relative('media')

# URL prefix for admin media -- CSS, JavaScript and images. Make sure to use a
# trailing slash.
# Examples: "http://foo.com/media/", "/media/".
ADMIN_MEDIA_PREFIX = '/django/djanet/media/'

# Make this unique, and don't share it with anybody.
SECRET_KEY = 'v7157zkeh1zubi9o5jd0=@e5%^53%!)c(uz$2u7fcq_cmd&!zz'

# List of callables that know how to import templates from various sources.
TEMPLATE_LOADERS = (
    'django.template.loaders.filesystem.Loader',
    'django.template.loaders.app_directories.Loader',
    # 'django.template.loaders.filesystem.load_template_source',
    # 'django.template.loaders.app_directories.load_template_source',
    # 'django.template.loaders.eggs.load_template_source',
)

MIDDLEWARE_CLASSES = (
    'django.middleware.common.CommonMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'djanet.middleware.session.SessionMiddleware',
)

ROOT_URLCONF = 'djanet.urls'

TEMPLATE_CONTEXT_PROCESSORS = (
      # "django.core.context_processors.auth",
      "django.core.context_processors.debug",
      "django.core.context_processors.i18n",
      "django.core.context_processors.media",
      "django.core.context_processors.request",
      'django.contrib.auth.context_processors.auth',
      'djanet.utils.utils.media_url',
      )

TEMPLATE_DIRS = (
      absolute("www", "templates")
    # Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
    # Always use forward slashes, even on Windows.
    # Don't forget to use absolute paths, not relative paths.
)

INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.messages',
    'django.contrib.admin',
    'djanet.djauth',
    'djanet.compartment',
    'djanet.termserver',
    'djanet.tools',
)
